package com.yiwyn.Structural.adapter;

public class Main {
    public static void main(String[] args) {

        Mobile mobile = new Mobile();

        Power220V power220V = new Power220V();
        Power5V power5V = new PowerAdapter(power220V);

        mobile.inputPower(power5V);
    }


    /**
     * 手机
     */
    static class Mobile {

        public void inputPower(Power5V power5V) {
            int i = power5V.provider5VPower();
            System.out.println("充电电压=" + i);
        }
    }

    /**
     * 5v接口
     */
    public interface Power5V {
        int provider5VPower();
    }

    /**
     * 220v接口
     */
    static class Power220V {
        public int provider220VPower() {
            return 220;
        }
    }


    // 电源适配
    static class PowerAdapter implements Power5V {

        private final Power220V power220V;

        public PowerAdapter(Power220V power220V) {
            this.power220V = power220V;
        }

        @Override
        public int provider5VPower() {
            int v220 = this.power220V.provider220VPower();
            return v220 - 215;
        }
    }


}